<template>
  <!-- 法规平台 -->
  <div class="app-container">
    <!-- <h1>法规平台</h1> -->
    <div class="boxlaw">
      <div class="comform">
        <ComForm
          ref="comForm"
          @EventReset="resetFn"
          @EventOnsubmit="queryFn"
          :list="comForm"
        >
        </ComForm>
      </div>

      <ComTable
        @handleCurrentChange="CurrentPageChangeFn"
        @handleSizeChange="currentPageSizeChangeFn"
        :key="random"
        :list="tableList"
        :modes="tableModes"
        :config="{ border: true, loading }"
        :pagination="{ total: paging.total, pageNum: paging.pageNum }"
      >
      </ComTable>
    </div>
  </div>
</template>

<script>
import ComTable from "../../../components/comTable.vue";
import ComForm from "../../../components/comForm.vue";
// import { getdocGetTypeApi } from "@/wss/api/ContentSupervision.js";

import { getCmVoucherListApi } from "@/wss/api/BusinessPlatform/AGP.js";
export default {
  name: "laws",
  dicts: ["sys_normal_disable"],
  components: { ComForm, ComTable },

  data() {
    return {
      initSelectValue: "",
      // 加载
      loading: false,
      paging: { pageNum: 1, pageSize: 10, status: "", total: 10 },
      // 切换筛选状态，不更新bug修复
      random: "",
      // 当前筛选的状态
      currentSelect: "",
      options: {
        value: "",
        title: "快速筛选",
        list: [
          {
            value: "",
            label: "全部",
          },
          {
            value: "0",
            label: "待编辑",
          },
          {
            value: "1",
            label: "审核中",
          },
          {
            value: "2",
            label: "审核失败",
          },

          {
            value: "4",
            label: "上架",
          },
          {
            value: "5",
            label: "下架",
          },
        ],
      },
      // 动态生成下拉列表的筛选条件
      dynamicFilter: {},
      // 表格的数据
      tableList: [],
      // 表格的列字段
      tableModes: [
        {
          type: "selection",
          label: "编号",
          mode: "index",
        },
        {
          showOverflowTooltip: true,
          width: 200,
          label: "商务姓名",
          mode: "cmName",
          showOverflowTooltip: true,
        },
        {
          label: "发放类型",
          mode: "type",
          effectiveStatus: true,
          width: 100,
          align: "center",
          isShowTag: true,
          options: [
            {
              l: "支出",
              v: 1,
              type: "warning",
            },
            {
              l: "自动",
              v: 2,
            },
            {
              l: "手动转入",
              v: 3,
            },
          ],
        },
        {
          label: "职等",
          mode: "level",
          showOverflowTooltip: true,
        },
        {
          label: "配比比例（%）",
          mode: "ratio",
          effectiveStatus: true,
          width: 100,
          align: "center",
        },
        {
          label: "促成订单额",
          mode: "orderPrice",
        },
        {
          label: "发放问金金额",
          mode: "amount",
        },
        {
          label: "发放时间",
          mode: "createTime",
        },
      ],
      comForm: {
        modes: [
          {
            placeholder: "请输入商务姓名",
            formType: "input",
            mode: "CmName",
            label: "商务经理",
            value: "",
          },
          {
            placeholder: "请选择类型",
            formType: "select",
            mode: "type",
            label: "发行类型",
            value: "",
            select: [],
          },
          {
            placeholder: "请输入职等",
            formType: "select",
            mode: "level",
            label: "职等",
            value: "",
            select: [],
          },
          {
            placeholder: "请选择日期",
            formType: "date",
            mode: "createTime",
            label: "发放日期",
            value: null,
            pickerType: "datetime",
          },
        ],
      },
    };
  },

  mounted() {
    this.getCmVoucherListFn(this.paging);
  },
  methods: {
    // 重设函数
    resetFn() {
      this.initSelectValue = "";
      this.romdom = Math.random();
      this.options.value = "";
      this.paging.status = "";
      console.log(this.paging, "重设");
    },
    // 当前页发生改变时候
    CurrentPageChangeFn(pageNUm) {
      this.paging.pageNum = pageNUm;
      this.getCmVoucherListFn(this.paging);
    },
    // 页容量发生改变时候
    currentPageSizeChangeFn(pageSize) {
      this.paging.pageSize = pageSize;
      this.getCmVoucherListFn(this.paging);
    },
    // 筛选数据
    queryFn(arr) {
      arr.forEach((item) => {
        for (const key in item) {
          this.paging[key] = item[key];
        }
      });
      this.currentSelect = this.initSelectValue;
      console.log(this.paging, "查询");
      this.paging.pageNum = 1;
      this.getCmVoucherListFn(this.paging);
    },
    // 获取列表数据
    async getCmVoucherListFn(pagination = null) {
      this.loading = true;
      let result = await getCmVoucherListApi(pagination);

      console.log(result, "问金池");
      if (result.code == 200) {
        this.tableList = JSON.parse(JSON.stringify(result.rows));
        this.paging.total = result.total;
        console.log(result.rows);

        result.rows.forEach((item, index) => {
          console.log(item);
          // 获取月份
          this.dynamicFilter.type ? "" : (this.dynamicFilter.type = []);
          this.dynamicFilter.level ? "" : (this.dynamicFilter.level = []);
          if (!this.dynamicFilter.type.includes(item.type)) {
            this.dynamicFilter.type.push(item.type);
          }
          if (!this.dynamicFilter.level.includes(item.level)) {
            this.dynamicFilter.level.push(item.level);
          }
        });

        this.comForm.modes.forEach((item) => {
          switch (item.mode) {
            case "type":
              item.select = this.arrTransformObj(this.dynamicFilter.type, [
                "",
                "支出",
                "自动",
                "手动转入",
              ]);

              break;
            case "level":
              item.select = this.arrTransformObj(this.dynamicFilter.level);
              break;
          }
        });

        this.loading = false;
      }
    },

    // row每一行的数据，去发放详细
    async clickLook(row) {
      this.$router.push({ path: "/fnancialPlatform/AGR/AGR-detail" });
    },
  },
};
</script>

<style lang ="scss" scoped>
.comform {
  margin-top: 20px;
}
</style>